<?php

// lookup the most recent instance
$query = "SELECT id, state, days, style, start_node, stale_dn, track_id"
   		." FROM n_adc WHERE style LIKE 'stale' AND state != 3";
$result = db_query($query);
if(!$result) {
	echo "error: wasn't able to find list in the instance\n";
	exit(1);
}
// loop through until we have the last instance
$instance = mysql_fetch_assoc($result);
while($next = mysql_fetch_assoc($result)) {
	$instance = $next;
}

// count ad objects pending deletion
$query = "SELECT * FROM n_adc_". $instance["id"] ." WHERE isIgnore=0";
$result = db_query($query);
if(!$result) {
	echo "error: wasn't able to find list in the instance\n";
	exit(1);
}
$pending_deletion = mysql_num_rows($result);

// count ad objects activity detected
$query = "SELECT * FROM n_adc_". $instance["id"] ." WHERE isIgnore=1";
$result = db_query($query);
if(!$result) {
	echo "error: wasn't able to find list in the instance\n";
	exit(1);
}
$activity_detected = mysql_num_rows($result);

// count exceptions current
$query = "SELECT * FROM n_adc_exceptions WHERE isElapsed=0";
$result = db_query($query);
if(!$result) {
	echo "error: wasn't able to find list in the instance\n";
	exit(1);
}
$exceptions_current = mysql_num_rows($result);

// count exceptions expired
$query = "SELECT * FROM n_adc_exceptions WHERE isElapsed=1";
$result = db_query($query);
if(!$result) {
	echo "error: wasn't able to find list in the instance\n";
	exit(1);
}
$exceptions_expired = mysql_num_rows($result);
?>

<tr bgcolor='white'><td colspan='2'>Stale
<tr bgcolor='white'><td>&nbsp;&nbsp;Pending Deletion
	<td align='right'><?php echo $pending_deletion; ?>
<tr bgcolor='white'><td>&nbsp;&nbsp;Activity Detected
	<td align='right'><?php echo $activity_detected; ?>
<tr bgcolor='white'><td align='right'>Total:
	<td align='right'><?php echo ($pending_deletion + $activity_detected); ?>
<tr bgcolor='white'><td colspan='2'>Exceptions
<tr bgcolor='white'><td>&nbsp;&nbsp;Current
	<td align='right'><?php echo $exceptions_current; ?>
<tr bgcolor='white'><td>&nbsp;&nbsp;Expired
	<td align='right'><?php echo $exceptions_expired; ?>
